<template>
  <div class="history-container">
    <header>
      <h1>聊天历史</h1>
    </header>
    <main>
      <div v-if="histories.length === 0" class="no-history">
        <p>暂无聊天历史</p>
      </div>
      <div v-else>
        <div class="history-item" v-for="history in histories" :key="history.id" @click="viewHistory(history.id)">
          <h3>{{ history.title }}</h3>
          <p>{{ history.time }}</p>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

export default {
  name: 'ChatHistory',
  setup() {
    const histories = ref([
      {
        id: 1,
        title: '与AI的对话1',
        time: '2023-07-15 14:30'
      },
      {
        id: 2,
        title: '与AI的对话2',
        time: '2023-07-14 10:15'
      },
      {
        id: 3,
        title: '与AI的对话3',
        time: '2023-07-13 09:45'
      }
    ])

    const router = useRouter()

    const viewHistory = (id) => {
      // 这里只是模拟查看历史，实际项目中需要根据id获取对应的历史记录
      alert(`查看ID为${id}的聊天历史`)
      router.push('/chat')
    }

    return {
      histories,
      viewHistory
    }
  }
}
</script>

<style scoped>
.history-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  padding: 10px 20px;
  background-color: #42b983;
  color: white;
  text-align: center;
}

main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background-color: #f9f9f9;
}

.no-history {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: #999;
}

.history-item {
  padding: 15px;
  margin-bottom: 10px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: background-color 0.3s;
}

.history-item:hover {
  background-color: #f0f0f0;
}

.history-item h3 {
  margin-bottom: 5px;
  color: #333;
}

.history-item p {
  color: #666;
  font-size: 14px;
}
</style>